<?php
require_once 'glob.php';
$page=$_REQUEST['page'];
$selfadminid=$_SESSION['adminid'];
$errmsg='对不起你没有权限进入该页面!';

switch ($_REQUEST['action']) {
	case 'list':
		check_admin_type('super',$errmsg);
		get_list('sn_admin', array(id,name,admintype,mail),'adminuserlist','adminuser_list.htm','fypage',$page,'where isdel = "N"','?action=list&');
		
		break;
	case 'add':
		check_admin_type('super',$errmsg);
		//管理员类型下拉
		$xueniao->assign('admintype',get_admintype());

		//创建编辑器下拉选项列表
		$editorlist=get_dirname('inc/editor');
		$xueniao->assign('editorlist',$editorlist);

		//创建语言包下拉选项列表
		$langlist=get_dirname('lang');
		$xueniao->assign('langlist',$langlist);

		//创建皮肤下拉列表
		$themlist=get_dirname('templates');
		$xueniao->assign('themlist',$themlist);

		//使用系统默认的编辑器语言包创创建管理员
		$sql='select editor,lang from sn_system';
		$defaultinfo=$db->getrow($sql);
		$xueniao->assign('defaultinfo',$defaultinfo);

		$xueniao->display('adminuser_info.htm');
		break;

	case 'edit':

		check_admin_type('super',$errmsg);

		if($_REQUEST['setadminid']=="" || $_REQUEST['setadminid']==null)
		{
			sys_msg('未指定用户,无法修改', 0);
			exit();
		}else {
			$setadminid=$_REQUEST['setadminid'];
		}

		//print_r(get_admintype());
		$xueniao->assign('admintype',get_admintype());

		//创建编辑器下拉选项列表
		$editorlist=get_dirname('inc/editor');
		$xueniao->assign('editorlist',$editorlist);

		//创建语言包下拉选项列表
		$langlist=get_dirname('lang');
		$xueniao->assign('langlist',$langlist);

		//创建皮肤下拉列表
		$themlist=get_dirname('templates');
		$xueniao->assign('themlist',$themlist);
		$xueniao->assign('adminid',$setadminid);
		get_info('sn_admin',array(name,mail,skin,lang,editor,admintype), 'admininfo', 'adminuser_info.htm','id = '.$setadminid);

		//	$xueniao->display('adminuser_info.htm');
		break;

	case 'adminset':
		//创建编辑器下拉选项列表
		$editorlist=get_dirname('inc/editor');
		$xueniao->assign('editorlist',$editorlist);

		//创建语言包下拉选项列表
		$langlist=get_dirname('lang');
		$xueniao->assign('langlist',$langlist);

		//创建皮肤下拉列表
		$themlist=get_dirname('templates');
		$xueniao->assign('themlist',$themlist);
		$xueniao->assign('setadminid',$adminid);
		get_info('sn_admin',array(name,mail,skin,lang,editor), 'admininfo', 'adminuser_set.htm','id = '.$selfadminid);


		break;
	case 'changepass':


		get_info('sn_admin',array(name), 'admininfo', 'adminuser_changepass.htm','id = '. $selfadminid);
		break;
	case 'insert':
		check_admin_type('super',$errmsg);

		if($_REQUEST['fm_name']!=="")
		{
			if (eqdata('sn_admin', 'name', $_REQUEST['fm_name'])==true) {
				sys_msg('添加失败，管理员名称不能重复',1);
			}
			

			$post=array(
			name=>$_REQUEST['fm_name'],
			password=>md5($_REQUEST['fm_password']),
			mail=>$_REQUEST['fm_mail'],
			editor=>$_REQUEST['fm_editor'],
			lang=>$_REQUEST['fm_lang'],
			skin=>$_REQUEST['fm_skin'],
			admintype=>$_REQUEST['fm_admintype']
			);
			$res=$db->insert('sn_admin',$post);
			if($res==true){
				sys_msg('管理员添加成功',0);
			}
		}else {
			sys_msg('添加失败，管理员名称不能为空',0);
			
		}


		break;

	case 'update':
		check_admin_type('super',$errmsg);
		if($_REQUEST['setadminid']=="" || $_REQUEST['setadminid']==null)
		{
			sys_msg('未指定用户,无法修改', 1);
			exit();
		}else {
			$setadminid=$_REQUEST['setadminid'];
		}

		$post=array(
		id=>$setadminid,
		//要更改的id
		mail=>$_REQUEST['fm_mail'],
		editor=>$_REQUEST['fm_editor'],
		lang=>$_REQUEST['fm_lang'],
		skin=>$_REQUEST['fm_skin'],
		admintype=>$_REQUEST['fm_admintype']
		);
		if($_REQUEST["fm_password"]!="" || $_REQUEST["fm_password"]!=null)
		{
			$post['password']=md5($_REQUEST['fm_password']);
		}

		$res=$db->update('sn_admin',$post,id);

		if($res==true){
			sys_msg('资料修改成功！',0);
		}

		break;

	case 'admin_set_update':
		$post=array(
		id=>$selfadminid,
		//要更改的id
		mail=>$_REQUEST['fm_mail'],
		editor=>$_REQUEST['fm_editor'],
		lang=>$_REQUEST['fm_lang'],
		skin=>$_REQUEST['fm_skin'],
		);
		$res=$db->update('sn_admin',$post,id);
		if($res==true){
			sys_msg('资料修改成功！',0);
		}

		break;
	case 'changepass_update':
		if($_REQUEST["fm_oldpassword"]!="" || $_REQUEST["fm_oldpassword"]!=null){
			$resp=$db->getrow('select password from sn_admin where id = '.$adminid);
			if(md5($_REQUEST["fm_oldpassword"])!=$resp['password'])
			{
				sys_msg('原密码错误，请重新填写!', 2);
				exit();
			}else {
				if($_REQUEST['fm_newpassword']!==$_REQUEST['fm_newpassword2'] || $_REQUEST['fm_newpassword']=="")
				{
					sys_msg('新密码不能为空，并要求和确认密码不一致!', 2);
					exit();
				}else{
					$post=array(
					id=>$selfadminid,
					//要更改的id
					password=>md5($_REQUEST['fm_newpassword'])
					);

					$res=$db->update('sn_admin',$post,id);
					if($res==true){
						sys_msg('密码修改成功！',0);
					}
				}
			}
		}


		break;

	default:
		check_admin_type('super',$errmsg);

		get_list('sn_admin', array(id,name,admintype,mail),'adminuserlist','adminuser_list.htm','fypage',$page,'where isdel = "N" and admintype != "super"','?action=list&');
		break;
}
?>